<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('定时任务列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>任务描述：</label>
                                <input type="text" name="taskExplain"/>
                                <input type="hidden" value ="1" name="cronType"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:cron:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:cron:remove')}]];
        var cronInteDwDatas = [[${@dict.getType('scheduler_task_unit')}]];
        var prefix = ctx + "system/cron";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit2/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "定时任务",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'cronId', 
                    title: '主键id',
                    visible: false
                },
                {
                    field: 'taskExplain', 
                    title: '任务描述'
                },
                {
                    field: 'status', 
                    title: '状态,1:正常;0:停用'
                },
                {
                    field: 'cronStrat', 
                    title: '定时任务开始'
                },
                {
                    field: 'cronEnd', 
                    title: '定时任务结束'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.cronId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(row.taskExplain == '在线奖励' || row.taskExplain == '财神降临'  || row.taskExplain == '福星来访'  || row.taskExplain == '战神入侵'   || row.taskExplain == '大日金乌') {
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="openChouJiangInfo(\'' + row.taskExplain + '\')"><i class="fa fa-edit"></i>详细配置</a>');
                        }
                        if(row.taskExplain == '充值排行榜' || row.taskExplain == '抽奖排行榜') {
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="exeTask(\'' + row.cronId + '\')"><i class="fa fa-edit"></i>执行一次</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
<script>
    function exeTask(id){
        var url = "exeTask";
        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: {cronId:id},
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function(result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess(result.msg);
                }  else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                }  else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            }
        };
        $.ajax(config)
    }


    function openChouJiangInfo(type,title, url, width, height, callback){
        //var ctx = window.location.host;
        var key = "";

        if(type == "大日金乌"){
            key = "darijinwu";
            title = "修改大日金乌配置"
        }
        if(type == "地府世道大会"){
            key = "difushidao";
            title = "修改地府世道大会配置"
        }
        if(type == "世道大会"){
            key = "shidaodahui";
            title = "修改世道大会配置"
        }
        if(type == "抽奖排行榜"){
            key = "choujiang";
            title = "修改抽奖排行榜配置"
        }
        if(type == "财神降临"){
            key = "caishen";
            title = "修改财神配置"
        }
        if(type == "福星来访"){
            key = "fuxing";
            title = "修改福星配置"
        }
        if(type == "战神入侵"){
            key = "zhanshen";
            title = "修改战神配置"
        }
        if(type == "在线奖励"){
            key = "online";
            title = "修改在线奖励配置"
        }
        if(key == ""){
            alert("敬请期待");
            return;
        }
        sessionStorage.setItem('keyName',key)
        var url = "queryCache";
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        if ($.common.isEmpty(title)) {
            title = false;
        }
        if ($.common.isEmpty(url)) {
            url = "/404.html";
        }
        if ($.common.isEmpty(width)) {
            width = 800;
        }
        if ($.common.isEmpty(height)) {
            height = ($(window).height() - 50);
        }
        if ($.common.isEmpty(callback)) {
            callback = function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(index, layero);
            }
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "修改积分抽奖信息",
            content: url,
            btn: [ '关闭','确定'],
            // 弹层外区域关闭
            shadeClose: true,
            yes: callback,
            cancel: function(index) {
                return true;
            }
        });

    }

</script>
</html>